package com.atguigu.gmall.order.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.order.ov.OrderConfirmRespVo;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.utils.UserAuthUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/inner/rpc/order")
public class OrderRpcController {

    @Autowired
    OrderBizService orderBizService;

    @Autowired
    OrderInfoService orderInfoService;

    /**
     * 获取订单确认页数据
     * @return
     */
    @GetMapping("/confirmdata")
    public Result<OrderConfirmRespVo> orderConfirmData(){

        OrderConfirmRespVo orderConfirmRespVo = orderBizService.getConfirmData();
        return Result.ok(orderConfirmRespVo);
    }

    /**
     * 根据订单Id查询订单
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public Result<OrderInfo> getOrderInfoById(@PathVariable Long id){

        Long userId = UserAuthUtils.getUserId();
        OrderInfo orderInfo = orderInfoService.getOrderInfoByIdAndUserId(id,userId);
        return Result.ok(orderInfo);
    }
}
